package project.dzz.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import project.dzz.manager.response.*;
import project.dzz.service.MESService;

@RestController
public class MESController {
    @Autowired
    private MESService mesService;

    /**
     * 添加任务
     *
     * @param taskStyle      任务1
     * @param batch          批次号
     * @param productlineNum 生产线号
     * @param planQuantity   计划数量
     * @param remark         备注
     * @param taskStatus     任务状态
     * @return
     */
    @RequestMapping("/addTask")
    @ResponseBody
    public TaskResponse addTask(String taskStyle, String batch, int productlineNum, int planQuantity,
                                String remark, int taskStatus) {
        int code = mesService.addTask(taskStyle, batch, productlineNum, planQuantity, remark, taskStatus);
        int count = 0;
        TaskResponse taskResponse = new TaskResponse(code, count);
        return taskResponse;
    }


    /**
     * 删除任务
     *
     * @param taskStyle      任务1
     * @param batch          批次号
     * @param productlineNum 生产线号
     * @return
     */
    @RequestMapping("/delTask")
    @ResponseBody
    public TaskResponse delTask(String taskStyle, String batch, int productlineNum) {
        int code = mesService.delTask(taskStyle, batch, productlineNum);
        int count = 0;
        TaskResponse taskResponse = new TaskResponse(code, count);
        return taskResponse;
    }
    /**
     * 加载任务
     */
    @RequestMapping("/getTask")
    @ResponseBody
    public GetTaskResponse getTask() {
        GetTaskResponse getTaskResponse=mesService.getTask();
        return getTaskResponse;
    }

    /**
     * 完成任务
     */
    @RequestMapping("/comTask")
    @ResponseBody
    public TaskResponse comTask(String taskStyle,String batch,int productlineNum) {
        TaskResponse taskResponse=mesService.comTask(taskStyle,batch,productlineNum);
        return taskResponse;
    }
    /**
     * 查询工序及对应参数名称
     */
    @RequestMapping("/getParaName")
    @ResponseBody
    public ParaResponse getParaName() {
        ParaResponse paraResponse = mesService.getParaName();
        return paraResponse;
    }


    /**
     * 查询部件名称
     *
     * @param
     * @return
     */
    @RequestMapping("/getComName")
    @ResponseBody
    public CompResponse getComName() {
        CompResponse compResponse = mesService.getComName();
        return compResponse;
    }

    /**
     * 查询产品生产明细
     *
     * @param
     * @param productCode 产品条码
     * @return
     */
    @RequestMapping("/getProInfo")
    @ResponseBody
    public DataResponse getProInfo(String productCode) {
        DataResponse dataResponse = mesService.getProInfo(productCode);
        return dataResponse;
    }

    /**
     * 根据产品批次号查询不合格数及不合格产品条码
     *
     * @param
     * @param batch 批次号
     * @return
     */
    @RequestMapping("/getBadPro")
    @ResponseBody
    public FailedResponse getBadPro(String processName, Integer productlineNum, String startTime, String endTime, Integer deviceNum, String batch, Integer stationNum, String employeeCode) {
        FailedResponse failedResponse = mesService.getBadPro(processName,productlineNum,startTime,endTime,deviceNum,batch,stationNum,employeeCode);
        return failedResponse;
    }

    /**
     * 查询所有工序
     *
     * @param
     * @return
     */
    @RequestMapping("/getProcess")
    @ResponseBody
    public ProcessResponse getProcess() {
        ProcessResponse processResponse = mesService.getProcess();
        return processResponse;
    }


    /**
     * 查询生产质量报表
     *
     * @param processName    工序名称
     * @param startTime      起始时间
     * @param endTime        截至时间
     * @param batch          批次号
     * @param productlineNum 批次号
     */
    @RequestMapping("/getProducts")
    @ResponseBody
    public ReportResponse getProducts(String processName, String startTime, String endTime, String batch,
                                      Integer productlineNum) {
        ReportResponse reportResponse = mesService.getProducts(processName, startTime, endTime, batch, productlineNum);
        return reportResponse;
    }

    /**
     * 员工报表
     *
     * @param employeeCode 员工条码
     */
    @RequestMapping("/getEmpInfos")
    @ResponseBody
    public EmployeeResponse getEmpInfos(String employeeCode) {
        EmployeeResponse employeeResponse = mesService.getEmpInfos(employeeCode);
        return employeeResponse;

    }

    /**
     * 安灯
     */
    @RequestMapping("/getAandonStatus")
    @ResponseBody
    public AndonResponse getAandonStatus() {
        AndonResponse andonResponse = mesService.getAndonStatus();
        return andonResponse;
    }

    /**
     * 安灯事件
     */
    @RequestMapping("/getAanEvents")
    @ResponseBody
    public AndonEventResponse getAanEvents() {
        AndonEventResponse andonEventResponse = mesService.getAanEvents();
        return andonEventResponse;
    }

    /**
     * 安灯事件确认
     *
     * @param contact        联系人
     * @param tel            联系电话
     * @param contactContent 联系内容
     * @param remark         附加信息
     */
    @RequestMapping("/doAanEvenCom")
    @ResponseBody
    public AndonResponse doAanEvenCom(String contact, String tel, String contactContent, String remark, String startTime, int andonStyle) {
        AndonResponse andonResponse = mesService.doAanEvenCom(contact, tel, contactContent, remark, startTime, andonStyle);
        return andonResponse;
    }

    /**
     * 系统设置
     *
     * @param processName   工序名称
     * @param processId     工序号
     * @param parameterName 参数名称
     * @param parameterId   参数号
     * @param componentName 部件名称
     * @param componentId   部件号
     */
    @RequestMapping("/doSysSettings")
    @ResponseBody
    public SysSetResponse doSysSettings(String processName, Integer processId, String parameterName,
                                        Integer parameterId, String componentName, Integer componentId) {
        SysSetResponse sysSetResponse = mesService.doSysSettings(processName, processId, parameterName, parameterId, componentName, componentId);
        return sysSetResponse;
    }


    /**
     * 查找系统设置
     */
    @RequestMapping("/getSysSettings")
    @ResponseBody
    public SysGetResponse getSysSettings() {
        SysGetResponse sysGetResponse = mesService.getSysSettings();
        return sysGetResponse;
    }

    /**
     * 电子看板
     */
    @RequestMapping("/getElect")
    @ResponseBody
    public ElectResponse getElect() {
        ElectResponse electResponse = mesService.getElect();
        return electResponse;
    }
    /**
     * Cp,Cpk计算
     */
    @RequestMapping("/getResult")
    @ResponseBody
    public CpResponse getResult(String parameterName,Integer count,String batch,Double usl,Double lsl,Integer productlineNum,Integer deviceNum,Integer stationNum){
        CpResponse cpResponse=mesService.getResult(parameterName,count,batch,usl,lsl,productlineNum,deviceNum,stationNum);
        return cpResponse;
    }
}
